const app = getApp()
import util from "../../utils/util";
import {
  GetColumnContent,
  GetVideoCenter,
  GetListMlink
} from "../../config/api";

Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    limit: 10,
    active: 0,
    mold: '',
    pid: '',
    type:'',
    notices: [], //公告公开的数据
    videoLists: [],
    isBottom: false,
    columnList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log('动态：', options);
    let that = this;
    let id = options.id;
    this.setData({
      pid: id
    })
    this.getColumnList()
    

  },
  getColumnList(){
    let that =this;
    util.apiRequest(GetListMlink, {
     // belongs: 3,
      vollege_id: app.globalData.vollege_id,
      pid:that.data.pid
    }, null).then(r => {
      console.log("子栏目：", r.data.data);
      that.setData({
        columnList: r.data.data, //子栏目
        type:r.data.data[0].type
      });
      this.getNewsList(0)
    }); //获取顶部子栏目
    
  },
  getNewsList(k) {
    console.log('page', this.data.page)
    let page =1
    if(k==1){
      page=this.data.page
    }
    let that = this;
    wx.showLoading({
      title: '玩命加载中',
    })
    util.apiRequest(GetColumnContent, {
      type: that.data.type,
      page: page,
      limit: that.data.limit,
      vollege_id: app.globalData.vollege_id
    }, null).then(r => {
      console.log('动态', r.data.data.data);
      // that.setData({
      //   notices: r.data.data.data
      // });
      if(k==0){
        var newList = r.data.data.data
      }else{
        var newList = that.data.notices.concat(r.data.data.data)
      }
      
     // var newList = that.data.notices.concat(r.data.data.data)
      if (r.data.data.data == '') {
        that.setData({
          //isBottom: true,
          notices: newList
        })
        wx.showToast({
          title: '暂无更多',
          icon: 'none',
        })
      } else {
        that.setData({
          notices: newList
        })
      }
      wx.hideLoading();
    });
  },
 /**
   * 改变切换选项卡默认激活状态
   */
  SwitchStatus: function(e) {
    // 传递的参数
    let index = e.currentTarget.dataset['index'];
    let type = e.currentTarget.dataset['type'];
    let is_flag =  e.currentTarget.dataset['flag'];
    let link =  e.currentTarget.dataset['link'];
     console.log('点击事件传递的参数：',link);
     console.log('is_flag',is_flag);
    // console.log('点击事件获得的数据：',this.data.richText);
    let that = this;
    that.setData({
      active: index,
      type:type
      //richText: that.data.columns[index].content.replace(/\<img/gi, '<img class="rich-img" '),
    });
    if(is_flag==3){
      
      wx.navigateTo({
        url: link
      })
    }else if(is_flag==1){
      that.getNewsList(0);
    }
    
    // console.log('富文本内容：',that.data.richText);

  },
  getVideoList() {
    let that = this;
    util.apiRequest(GetVideoCenter, {
      vollege_id: app.globalData.vollege_id
    }, null).then(r => {
      console.log('视频：', r.data.data.data);
      that.setData({
        videoLists: r.data.data.data
      });
    });
  },


  

  /**
   * 跳转到详情页面
   */
  ToMessageDetail: function(e) {
    let item = e.currentTarget.dataset['item'];
    console.log("点击事件传递的参数：", item.id);
    wx.navigateTo({
      url: '/pages/newsDetail/newsDetail?id=' + item.id
    });
  },

  // 跳转视频详情
  toDetail(e) {
    console.log(e)
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/shipin/shipinDetail/shipinDetail?id=' + id,
    })
  },


  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    var that = this;
    var page = this.data.page;
    page++;
    that.setData({
      page: page
    })

    that.getNewsList(1);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})